// AGWall.cpp: implementation of the CAGWall class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "resource.h"
#include "AGWall.h"
#include "AGUtil.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CAGWall::CAGWall() : CAGBase()
{
	m_arrWin.setLogicalLength(0);
	m_dLeftThick	= 0.0;
	m_dRightThick	= 0.0;
	m_nUseCount		= 0;
	GUID guid;
	CoCreateGuid(&guid);
	m_GUID = GUIDToString(guid);
}

CAGWall::~CAGWall()
{

}


void CAGWall::AddWindow( const CAGWindow& win )
{
	m_arrWin.append(win);
}
void CAGWall::SetWindow(const CWindowArray& winArr)
{
	m_arrWin.setLogicalLength(0);
	m_arrWin = winArr;
}

CWindowArray CAGWall::GetWindow() const
{
	return m_arrWin;
}

CWindowArray CAGWall::GetWindow( eSTRUCTTYPE structType ) const
{
	CWindowArray winArr;
	int nCount = m_arrWin.length();
	for ( int j = 0; j < nCount; ++j )
	{
		if ( m_arrWin.at(j).GetStructType() == structType )
		{
			winArr.append(m_arrWin.at(j));
		}
	}
	return winArr;
}


void CAGWall::SetLeftThick( double dLeftThick )
{
	m_dLeftThick = dLeftThick;
}

double CAGWall::GetLeftThick() const
{
	return m_dLeftThick;
}

void CAGWall::SetRightThick( double dRightThick )
{
	m_dRightThick = dRightThick;
}

double CAGWall::GetRightThick() const
{
	return m_dRightThick;
}


void CAGWall::SetUseCount( int nUseCount )
{
	m_nUseCount = nUseCount;
}

int CAGWall::GetUseCount() const
{
	return m_nUseCount;
}


double CAGWall::GetSectionArea() const
{
	return m_dWidth * (m_dLeftThick + m_dRightThick);
}

double CAGWall::GetWindowArea( eSTRUCTTYPE eType, ePOSITION ePos ) const
{
	double dArea = 0.0;
	if ( ePos != m_ePosition )
	{
		return dArea;
	}
	for ( int j = 0; j < m_arrWin.length(); ++j )
	{
		if ( eType == m_arrWin.at(j).GetStructType() )
		{
			dArea += m_arrWin.at(j).GetArea();
		}
	}
	return dArea;
}

double CAGWall::GetWindowArea( eSTRUCTTYPE eType ) const
{
	double dArea = 0.0;
	for ( int j = 0; j < m_arrWin.length(); ++j )
	{
		if ( eType == m_arrWin.at(j).GetStructType())
		{
			dArea += m_arrWin.at(j).GetArea();
		}
	}
	return dArea;
}

double CAGWall::GetWindowArea() const
{
	double dArea = 0.0;
	for ( int j = 0; j < m_arrWin.length(); ++j )
	{
		dArea += m_arrWin.at(j).GetArea();
	}
	return dArea;
}

bool CAGWall::IsA(const CAGWall& wall)
{
// 	if ( m_GUID.Data1 == wall.m_GUID.Data1 && m_GUID.Data2 == wall.m_GUID.Data2 && m_GUID.Data3 == wall.m_GUID.Data3 )
// 	{
// 		for ( int i = 0; i < 8; ++i )
// 		{
// 			if ( m_GUID.Data4[i] != wall.m_GUID.Data4[i] )
// 			{
// 				return false;
// 			}
// 		}
// 		return true;
// 	}
	return (m_GUID.CompareNoCase(wall.m_GUID) == 0);
}

void CAGWall::SetPosition( ePOSITION pos )
{
	m_ePosition = pos;
	CWindowArray tmpWimAry;
	for ( int j = 0; j < m_arrWin.length(); ++j )
	{
		CAGWindow win = m_arrWin.at(j);
		win.SetPosition(pos);
		tmpWimAry.append(win);
	}
	m_arrWin.setLogicalLength(0);
	m_arrWin.append(tmpWimAry);
}